package com.heaven.service;

import com.heaven.mapper.HonorMapper;
import com.heaven.pojo.Honor;
import com.heaven.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
public class HonorServiceImpl implements HonorService{
    @Autowired
    private HonorMapper honorMapper;
    @Override
    public PageResult honorList(PageResult pageResult) {
        int size=pageResult.getPageSize();
        int startNum=(pageResult.getPageNum()-1)*size;
        String query=pageResult.getQuery();

        List<Honor> row=honorMapper.honorList(size,startNum,query);
        long total=honorMapper.findHonorList(query);
        pageResult.setRows(row).setTotal(total);
        return pageResult;
    }

    @Override
    public Honor honorById(Integer id) {
       return honorMapper.honorById(id);
    }

    @Override
    @Transactional
    public void addHonor(Honor honor) {
        honor.setHonortime(new Date());
        honorMapper.addHonor(honor);
    }

    @Override
    @Transactional
    public void deleteById(Integer id) {
        honorMapper.deleteById(id);
    }

    @Override
    @Transactional
    public void updataHonor(Honor honor) {
        honor.setHonortime(new Date());
        honorMapper.updataHonor(honor);
    }
}
